package com.jing.service.impl;

import com.jing.domain.Vo.ProductAttributsVO;
import com.jing.domain.po.ProducAttributetCategoryPO;
import com.jing.domain.po.ProductAttributsPO;
import com.jing.mapper.ProductCategoryTypemapper;
import com.jing.service.ProductCategoryTypeService;
import com.jing.util.FastUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author：wp
 * @Package：com.jing.service.impl
 * @Project：jing
 * @name：ProductCategoryTypeServiceimpl
 * @Date：2024/5/26 14:28
 */
@Service
@Slf4j
public class ProductCategoryTypeServiceimpl implements ProductCategoryTypeService {

    @Autowired
    private ProductCategoryTypemapper productCategoryTypemapper;
    @Autowired
    private FastUtil fastUtil;
    @Override
    public List<ProductAttributsVO> list(Integer pageNum, Integer pageSize) {
        log.info ( "impl:传入参数是{}{},", pageNum,pageSize);
        ProductAttributsPO vos = new ProductAttributsPO ();
        List<ProductAttributsPO> list=productCategoryTypemapper.list();
        if(vos.getPageSize () > list.size () ||vos.getPageNum () > list.size () ){
            throw new RuntimeException ();
        }
        ArrayList<ProductAttributsVO> arrayList = new ArrayList<> ();
        for ( ProductAttributsPO producAttributetCategoryPO :list) {
            ProductAttributsVO vo = new  ProductAttributsVO ();
            BeanUtils.copyProperties(producAttributetCategoryPO,vo);
            arrayList.add ( vo );
        }
        return arrayList;
    }
    @Override
    public void del(Integer id) {
        productCategoryTypemapper.del(id);
        if (false){
            throw new RuntimeException ();
        }
    }

    @Override
    public String img(MultipartFile file) {
        try {
            String upload = fastUtil.upload ( file );
            return "http://122.51.81.125:8888/"+upload;
        } catch (Exception e) {
            e.printStackTrace ();
        }
        return null;
    }

    @Override
    public void add(ProductAttributsVO name) {
        productCategoryTypemapper.add(name);
        if (false){
            throw new RuntimeException ("错误");
        }

    }

    @Override
    public void up(ProductAttributsVO pms) {
        productCategoryTypemapper.update(pms);
        if (false){
            throw new RuntimeException ("错误");
        }
    }

    @Override
    public Object pac() {
        List<ProducAttributetCategoryPO> list=productCategoryTypemapper.pac();
return list;
    }

    @Override
    public Object id(Integer id) {
        List<ProductAttributsVO> list=productCategoryTypemapper.id(id);
        return list;
    }
}
